home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
1116.ZIP
/
TOOLKIT.ARC
/
STDIO.H
< prev
next >
Wrap
Text File
|
1979-12-31
|
9KB
|
222 lines
/* STDIO.H written by Wayne Pearson for Small C:PC
valid calls are:
printf("%d",65); display the decimal integer 65
printf("%h",65); display the hexadecimal integer 41
printf("%o",65); display the octal integer 101
printf("%b",65); display the binary integer 1000001
printf("\nHello\n\nworld\n",0); display string with embedded line feeds
prnchar(65); print 'A' on your printer
prnstr("Hello"); print the string Hello on your printer
prnf("%d",65,fptr); prints the decimal integer 65 on your printer
prnf("%h",65,fptr); prints the hexadecimal integer 41 on your printer
prnf("%o",65,fptr); prints the octal integer 101 on your printer
prnf("%b",65,fptr); prints the binary integer 1000001 on your printer
prnf("\nHello\n\nworld\n",0,fptr); prints string with embedded line feeds
*/
printf(pf_1,pf_2d)
char pf_1[]; int pf_2d;
{
if((pf_1[0] == '%')&(pf_1[1] == 'd')) disp_dec(10,pf_2d);
else if((pf_1[0] == '%')&(pf_1[1] == 'h')) disp_hex(pf_2d);
else if((pf_1[0] == '%')&(pf_1[1] == 'o')) disp_dec(8,pf_2d);
else if((pf_1[0] == '%')&(pf_1[1] == 'b')) disp_bin(pf_2d);
else disp_str(pf_1);
}
disp_dec(base_n,pf_2)
int base_n, pf_2;
{
int dec_100, dec_10, dec_1, base_nn;
base_nn = base_n * base_n;
if(pf_2 >= base_nn) dec_100 = pf_2 / base_nn; else dec_100 = 0;
if(pf_2 >= base_n)
{
dec_10 = pf_2 - dec_100 * base_nn;
dec_10 = dec_10 / base_n;
}
else dec_10 = 0;
if(pf_2 >= base_nn)
{
dec_1 = pf_2 - dec_100 * base_nn - dec_10 * base_n;
if(((dec_100 * base_nn) % base_nn) >= (base_nn/2 -1))--dec_1;
if(((dec_10 * base_n) % base_n) >= (base_n / 2 - 1 ))--dec_1;
}
if((pf_2 < base_nn)&(pf_2 >= base_n))
{
dec_1 = pf_2 -dec_10 * base_n;
if(((dec_10 * base_n) % base_n) >= (base_n / 2 - 1 ))--dec_1;
}
if(pf_2 < base_n) dec_1 = pf_2;
dec_100 = dec_100 + 48; dec_10 = dec_10 + 48; dec_1 = dec_1 + 48;
if(dec_100 > 48) putchar(dec_100);
if(((dec_100 > 48)&(dec_10 >= 48))|(dec_10 > 48)) putchar(dec_10);
putchar(dec_1);
}
disp_hex(pf_2h)
int pf_2h;
{
int hex_16, hex_1;
if(pf_2h >= 16)
{
hex_16 = pf_2h / 16; hex_1 = pf_2h - hex_16 * 16;
if(((hex_16 * 16) % 16) >= 8) --hex_1;
}
else { hex_16 = 0; hex_1 = pf_2h; }
if(hex_16 > 9) hex_16 = hex_16 + 7;
if(hex_1 > 9) hex_1 = hex_1 + 7;
hex_16 = hex_16 + 48; hex_1 = hex_1 + 48;
if(hex_16 > 48) putchar(hex_16); putchar(hex_1);
}
disp_bin(pf_2)
int pf_2;
{
int bin_8,bin_7,bin_6,bin_5,bin_4,bin_3,bin_2,bin_1,bin_mod;
bin_8 =bin_7 =bin_6 =bin_5 =bin_4 =bin_3 =bin_2 =bin_1 =0;
bin_mod = pf_2 / 128; if(bin_mod > 0) bin_8 = 1;
bin_mod = pf_2 / 64; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_7 = 1;
bin_mod = pf_2 / 32; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_6 = 1;
bin_mod = pf_2 / 16; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_5 = 1;
bin_mod = pf_2 / 8; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_4 = 1;
bin_mod = pf_2 / 4; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_3 = 1;
bin_mod = pf_2 / 2; bin_mod = bin_mod % 2;
if(bin_mod > 0) bin_2 = 1;
bin_mod = pf_2 % 2; if(bin_mod > 0) bin_1 = 1;
if(pf_2 > 255) bin_8 = 40;
putchar(bin_8 + 48); putchar(bin_7 + 48); putchar(bin_6 + 48);
putchar(bin_5 + 48); putchar(bin_4 + 48); putchar(bin_3 + 48);
putchar(bin_2 + 48); putchar(bin_1 + 48);
}
disp_str(str_nm)
char str_nm[];
{
char chr_str,str_end; int str_lcv; str_end='a'; str_lcv = 0;
while(str_end != 0)
{
str_end = str_nm[str_lcv];
if(str_end == '\') {++str_lcv; putchar(13);}
else {chr_str = str_nm[str_lcv]; putchar(chr_str);}
++str_lcv;
}
}
prnstr(str_name)
char str_name[];
{
char str_chr; int prn_lcv; prn_lcv = 0;
while(str_chr != 0)
{
str_chr = str_name[prn_lcv];
pcdos(5,str_chr); ++prn_lcv;
}
}
prnchar(chr_name)
char chr_name;
{ pcdos(5,chr_name); return(chr_name); }
prnf(f_1,f_2d)
char f_1[]; int f_2d;
{
if((f_1[0] == '%')&(f_1[1] == 'd')) prn_dec(10,f_2d);
else if((f_1[0] == '%')&(f_1[1] == 'h')) prn_hex(f_2d);
else if((f_1[0] == '%')&(f_1[1] == 'o')) prn_dec(8,f_2d);
else if((f_1[0] == '%')&(f_1[1] == 'b')) prn_bin(f_2d);
else prn_str(f_1);
}
prn_dec(ase_n,f_2)
int ase_n, f_2;
{
int ec_100, ec_10, ec_1, ase_nn;
ase_nn = ase_n * ase_n;
if(f_2 >= ase_nn) ec_100 = f_2 / ase_nn; else ec_100 = 0;
if(f_2 >= ase_n)
{
ec_10 = f_2 - ec_100 * ase_nn;
ec_10 = ec_10 / ase_n;
}
else ec_10 = 0;
if(f_2 >= ase_nn)
{
ec_1 = f_2 - ec_100 * ase_nn - ec_10 * ase_n;
if(((ec_100 * ase_nn) % ase_nn) >= (ase_nn/2 -1)) --ec_1;
if(((ec_10 * ase_n) % ase_n) >= (ase_n / 2 - 1 )) --ec_1;
}
if((f_2 < ase_nn)&(f_2 >= ase_n))
{
ec_1 = f_2 - ec_10 * ase_n;
if(((ec_10 * ase_n) % ase_n) >= (ase_n / 2 - 1 )) --ec_1;
}
if(f_2 < ase_n) ec_1 = f_2;
ec_100 = ec_100 + 48; ec_10 = ec_10 + 48; ec_1 = ec_1 + 48;
if(ec_100 > 48) prnchar(ec_100);
if(((ec_100 > 48)&(ec_10 >= 48))|(ec_10 > 48)) prnchar(ec_10);
prnchar(ec_1);
}
prn_hex(f_2h)
int f_2h;
{
int ex_16, ex_1;
if(f_2h >= 16)
{
ex_16 = f_2h / 16; ex_1 = f_2h - ex_16 * 16;
if(((ex_16 * 16) % 16) >= 8) --ex_1;
}
else { ex_16 = 0; ex_1 = f_2h; }
if(ex_16 > 9) ex_16 = ex_16 + 7;
if(ex_1 > 9) ex_1 = ex_1 + 7;
ex_16 = ex_16 + 48; ex_1 = ex_1 + 48;
if(ex_16 > 48) prnchar(ex_16); prnchar(ex_1);
}
prn_bin(zf_2)
int zf_2;
{
int in_8,in_7,in_6,in_5,in_4,in_3,in_2,in_1,in_mod;
in_8 =in_7 =in_6 =in_5 =in_4 =in_3 =in_2 =in_1 =0;
in_mod = zf_2 / 128; if(in_mod > 0) in_8 = 1;
in_mod = zf_2 / 64; in_mod = in_mod % 2;
if(in_mod > 0) in_7 = 1;
in_mod = zf_2 / 32; in_mod = in_mod % 2;
if(in_mod > 0) in_6 = 1;
in_mod = zf_2 / 16; in_mod = in_mod % 2;
if(in_mod > 0) in_5 = 1;
in_mod = zf_2 / 8; in_mod = in_mod % 2;
if(in_mod > 0) in_4 = 1;
in_mod = zf_2 / 4; in_mod = in_mod % 2;
if(in_mod > 0) in_3 = 1;
in_mod = zf_2 / 2; in_mod = in_mod % 2;
if(in_mod > 0) in_2 = 1;
in_mod = zf_2 % 2; if(in_mod > 0) in_1 = 1;
if(zf_2 > 255) in_8 = 40;
prnchar(in_8 + 48); prnchar(in_7 + 48); prnchar(in_6 + 48);
prnchar(in_5 + 48); prnchar(in_4 + 48); prnchar(in_3 + 48);
prnchar(in_2 + 48); prnchar(in_1 + 48);
}
prn_str(tr_nm)
char tr_nm[];
{
char hr_str,tr_end; int tr_lcv; tr_end='a'; tr_lcv = 0;
while(tr_end != 0)
{
tr_end = tr_nm[tr_lcv];
if(tr_end == '\') {++tr_lcv; prnchar(13);}
else {hr_str = tr_nm[tr_lcv]; prnchar(hr_str);}
++tr_lcv;
}
}